package com.walterlife.dp.CompositeDP;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class Drawing implements Shape {

    private List<Shape> shapes = new ArrayList<Shape>();
    private String name;

    private static Logger logger = Logger.getLogger(Drawing.class);

    public void draw(String color) {
        for(Shape shape: shapes) {
            shape.draw(color);
        } 
    }

    public Drawing(String name) {
        this.name= name; 
    } 

    public void addShapes(Shape shape) {
        if(shape == null) {
            logger.error("Drawing addShapes: shape is null, not valid!!!");        
        } else if(shapes.contains(shape)) {
            logger.warn("Drawing addShapes: shape " + shape.getName() + " is already existing!!!");        
        } else {
            shapes.add(shape);
        } 
    } 

    public void removeShapes(Shape shape) {
        if(!shapes.remove(shape)) {
            logger.warn("Drawing removeShapes: shape does not exist!!!");        
       } 
    } 

    public void clear() {
        logger.info("Drawing clear: clear all shape!!!");
        shapes.clear();
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
}
